<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日志开关</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div style="margin-top: 10px">
    <table id="sysLogSwitchTable" lay-filter="sysLogSwitchTable"></table>
</div>
<!-- 头部工具栏 -->
<script type="text/html" id="sysLogSwitchHeaderToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" wintitle="新增数据" areaw='500px' areah="260px" requrl="{{ serverPath.systemPath + layui.setter.sysLinkPath}}sysLogSwitch/view/add" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>新增</span>
        </a>
    </div>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="sysLogSwitchRightToolsBar">
    {{# if(d.fromType == 1){ }}
    <!-- 如果调用公共删除js，并且页面不需要分页会有问题，需要在删除按钮上增加isOpenPage="false"属性  -->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" requrl="{{ serverPath.systemPath + layui.setter.sysLinkPath}}sysLogSwitch/del" isOpenPage="false">删除</a>
    <a class="layui-btn layui-btn-xs"  lay-event="edit" wintitle="编辑" areaw='500px' areah="260px" requrl="{{ serverPath.systemPath + layui.setter.sysLinkPath}}sysLogSwitch/view/add?id={{d.id}}" lay-event="add">编辑</a>
    {{# }}}
</script>
<script type="text/html" id="status-switchTpl">
    <input type="checkbox" name="status" lay-skin="switch" lay-text="开启|关闭" lay-filter="status-switch"
           value="{{ d.id }}" model="{{d.model}}" memo="{{d.memo}}" fromType="{{d.fromType}}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter','jquery', 'form', 'common','totalFilter','commons'], function () {
        var $ = layui.$
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var totalFilter = layui.totalFilter;
        common.tableSort('sysLogSwitchTable');
        var tableH=commons.tabHeight();
        //第一个实例
        table.render({
            elem: '#sysLogSwitchTable'
            ,height:tableH
            ,autoSort:true  //是否排序
            ,url: serverPath.systemPath + setter.sysLinkPath + 'sysLogSwitch/list'
            ,page: false //开启分页
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: '#sysLogSwitchHeaderToolsBar'
            ,method: 'post'
            ,autoSort: true
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'model', title: '模块名称',sort:true}
                ,{field: 'memo', title: '备注',sort:true}
                ,{field: 'fromType', title: '类型',sort:true, sortname:'FROM_TYPE', templet: function (d) {
                        if (d.fromType == '0') {
                            return '<span style="color:red">内置模块<span>';
                        }
                        if (d.fromType == '1') {
                            return '扩展模块';
                        }
                        return '';
                    }}
                ,{field: 'status', title: '状态',sort:true, templet: '#status-switchTpl'}
                ,{fixed: 'right',align: 'center',title: '管理',toolbar: '#sysLogSwitchRightToolsBar'}
            ]]
        });

        totalFilter.init('sysLogSwitchTable');

        //监听开关
        form.on('switch(status-switch)', function(obj){

            var model = $(obj.elem).attr("model");
            var memo = $(obj.elem).attr("memo");
            var fromType = $(obj.elem).attr("fromType");
            var status = obj.elem.checked?1:0;//true=1为开启，false=0为关闭
            $.ajax({
                url: serverPath.systemPath + setter.sysLinkPath + "sysLogSwitch/switchStatus",
                type: "post",
                contentType: 'application/json',
                dataType: 'json',
                data: JSON.stringify({id:this.value,status:status,model:model,memo:memo,fromType:fromType}),
                success: function (data) {
                    table.reload('sysLogSwitchTable');
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("更新失败");
                    table.reload('sysLogSwitchTable');
                }
            });
        });
        //监听头部内部工具栏
        common.tableTool({
            name: 'sysLogSwitchTable'
        });

        table.on('toolbar(sysLogSwitchTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: _this.getAttribute('wintitle'),
                        area: [_this.getAttribute('areaw'), _this.getAttribute('areah')],
                        content: _this.getAttribute('requrl')
                    });
                    break;
                case "query":
                    common.tableConditionRender('sysLogSwitchTable','sysLogSwitchQueryForm',{where:{}},false);
                    break;
                case "clears":
                    common.tableConditionRender('sysLogSwitchTable','sysLogSwitchQueryForm',{where:{}},true);
                    break;
            };
        });

    });
</script>

<style>
    .tablesize .layui-table-tool {
        padding-bottom: 0;
    }

    .tablesize .layui-table-tool-temp {
        padding-right: 0;
    }

    .selch div {
        display: inline-block;
    }

    .selch .layui-form-label {
        width: 62px;
    }

    .selch div input {
        border-radius: 4px;
        float: left;
        width: 132px;
    }

    .selch .pullsel .xm-input {
        border-radius: 4px;
        width: 246px;
    }

    .selch .pullsel .xm-cz {
        margin-right: 11px !important;
    }

    .selch .pullsel .xm-select-parent dd > .xm-cz-group .xm-cz i {
        margin-right: 6px;
    }
    .layui-table-page{
        display: none;
    }
</style>
</body>
</html>